home *** CD-ROM | disk | FTP | other *** search
/ Programming Microsoft Visual Basic .NET / Programming Microsoft Visual Basic .NET (Microsoft Press)(X08-78517)(2002).bin / 02 modules and namespaces / modulesdemo / classes.vb < prev    next >
Encoding:
Text File  |  2001-09-11  |  1.4 KB  |  59 lines

  1. ' the Person class is used to test inheritance
  2.  
  3. Public Class Person
  4.     Public Const Title As String = "Mr. "
  5.  
  6.     Public FirstName As String
  7.     Public LastName As String
  8.  
  9.     Function CompleteName() As String
  10.         CompleteName = FirstName & " " & LastName
  11.     End Function
  12.  
  13.  
  14. End Class
  15.  
  16. ' The Employee class inherits from Person
  17.  
  18. Class Employee
  19.     Inherits Person
  20.  
  21.     Public BirthDate As Date                ' A new field
  22.  
  23.     Function ReverseName() As String        ' A new method
  24.         ReverseName = LastName & ", " & FirstName
  25.     End Function
  26. End Class
  27.  
  28. ' an example of structure that contains a fixed length string
  29.  
  30. Structure PersonStruct
  31.     Dim FirstName As String
  32.     Dim LastName As String
  33.     Public Address As String
  34.     Private SSN As String
  35.  
  36.     ' Simulate a fixed-length string.
  37.     Dim ZipCode As Microsoft.VisualBasic.Compatibility.VB6.FixedLengthString
  38.  
  39.     ' A constructor for this structure.
  40.     Sub New(ByVal firstName As String, ByVal lastName As String)
  41.         Me.FirstName = FirstName
  42.         Me.LastName = LastName
  43.         ' Initialize the fixed-length string.
  44.         ZipCode = New Microsoft.VisualBasic.Compatibility.VB6.FixedLengthString(10)
  45.     End Sub
  46.  
  47.  
  48.     Function CompleteName() As String
  49.         CompleteName = FirstName & " " & LastName
  50.     End Function
  51. End Structure
  52.  
  53. ' a class used to test performance of operation shorthands
  54.  
  55. Class Test
  56.     Public Value As Integer
  57. End Class
  58.  
  59.